home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 32 / Mac Magazin and MacEasy Magazine CD - Issue 32.iso / Grafik & Text / OzTeX3.0 / MetaPost / Inputs / string.mp < prev    next >
Text File  |  1996-08-24  |  763b  |  32 lines

  1. % String manipulation routines for MetaPost
  2. % It is harmless to input this file more than once.
  3.  
  4.  
  5. vardef isdigit primary d =
  6.   ("0"<=d)and(d<="9") enddef;
  7.  
  8.  
  9. % Number of initial characters of string s where `c <character>' is true
  10. vardef cspan(expr s)(text c) =
  11.   0
  12.   for i=1 upto length s:
  13.     exitunless c substring (i-1,i) of s;
  14.     + 1
  15.   endfor
  16. enddef;
  17.  
  18.  
  19. % String s is composed of items separated by white space.  Lop off the first
  20. % item and the surrounding white space and return just the item.
  21. vardef loptok suffix s =
  22.   save t, k;
  23.   k = cspan(s," ">=);
  24.   if k>0: s:=substring(k,infinity) of s; fi
  25.   k := cspan(s," "<);
  26.   string t;
  27.   t = substring (0,k) of s;
  28.   s := substring (k,infinity) of s;
  29.   s := substring (cspan(s," ">=),infinity) of s;
  30.   t
  31. enddef;
  32.